package com.atguigu.gmall.order.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.order.biz.OrderBizService;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.atguigu.gmall.order.vo.OrderSplitResp;
import com.atguigu.gmall.order.vo.OrderSubmitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "提交订单API")
@RequestMapping("/api/order")
@RestController
public class OrderApiController {

    @Autowired
    OrderBizService orderBizService;

    //  http://api.gmall.com/api/order/auth/submitOrder?tradeNo=ATGUIGU-1671804086578-3
    @ApiOperation("提交订单")
    @PostMapping("/auth/submitOrder")
    public Result submitOrder (@RequestParam("tradeNo") String tradeNo,
                               @Valid @RequestBody OrderSubmitVo orderSubmitVo){
        //提交订单方法  雪花算法生成的orderId 以字符串方式返回给前端
        Long orderId = orderBizService.submitOrder(tradeNo,orderSubmitVo);
        return Result.ok(orderId + "");
    }

    //库存系统：http://api.gmall.com/api/order/orderSplit
    @ApiOperation("拆单")
    @PostMapping("/orderSplit")
    public List<OrderSplitResp> orderSplit (@RequestParam("orderId") Long orderId,
                                            @RequestParam("wareSkuMap")String json){
        //拆单==》把一个大订单拆分成多个子订单
        List<OrderSplitResp> respList= orderBizService.orderSplit(orderId,json);
        return respList;
    }
}
